package com.baseweb.webadmin.controller.admin;


import com.baseweb.webadmin.alipay.config.AlipayConfig;
import com.baseweb.webadmin.alipay.util.AlipayNotify;
import com.baseweb.webadmin.alipay.util.AlipayParams;
import com.baseweb.webadmin.alipay.util.AlipaySubmit;
import com.baseweb.webadmin.controller.BaseController;
import com.baseweb.webadmin.core.constants.*;
import com.baseweb.webadmin.core.model.bvo.*;
import com.baseweb.webadmin.core.model.pojo.*;
import com.baseweb.webadmin.core.util.*;
import com.baseweb.webadmin.service.AccountService;
import com.baseweb.webadmin.service.ContentService;
import com.baseweb.webadmin.service.UserOrderService;
import com.baseweb.webadmin.service.UserService;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;

@Controller
@RequestMapping(value = "/order")
public class OrderController extends BaseController {

    private static final Logger LOG = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private UserOrderService userOrderService;

    @Autowired
    private AccountService accountService;

    @Autowired
    private UserService userService;

    @Autowired
    private ContentService contentService;

    private String PREFIX = "/order/";

    @RequestMapping(value = "/orderManage")
    public String orderManage(Model model) {
        model.addAttribute("statusList", OrderStatus.getAllData());
        model.addAttribute("payStatusList", OrderPayStatus.getAllData());

//        List<ByChannel> channelList = contentService.selectChannelListByPage(null, null, null, 0, Integer.MAX_VALUE);
//
//        Map<String, String> channelMap = new HashMap<String, String>();
//        if (channelList != null && channelList.size() > 0){
//            for (ByChannel current : channelList){
//                channelMap.put(current.getId().toString(), current.getName());
//            }
//        }
//
//        model.addAttribute("channelMap", channelMap);

        return PREFIX + "orderManage";
    }

    @RequestMapping(value = "/getOrderList")
    public void getOrderList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "50") Integer pageSize,
                             @RequestParam(value = "mobile",required = false) String mobile,
                             @RequestParam(value = "status",required = false) Integer status,
                             @RequestParam(value = "pay_status",required = false) Integer pay_status,
                                Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

//        User user = getCurrentUser();
        List<ByUserOrderInfoBvo> list = new ArrayList<ByUserOrderInfoBvo>();

        Integer biz_user_id = null;

        if (StringUtils.isNotBlank(mobile)) {
            User user = userService.selectByName(mobile);
            if (user != null){
                biz_user_id = user.getId();
            }
        }


        List<ByUserOrder> byUserOrders = userOrderService.selectOrderListByBizUser(null, biz_user_id, status, pay_status,(page-1)*pageSize, pageSize);
        if (byUserOrders != null && byUserOrders.size()>0){
            for(ByUserOrder current : byUserOrders){
                User bizUser = userService.selectUserById(current.getBizUserId());
                list.add(ByUserOrderInfoBvo.copyFrom(current, userService.selectUserById(current.getUserId()),
                        UserInfoBvo.copyFrom(bizUser, null, contentService.findChannel(bizUser.getBizWorkType()))));
            }
        }

        int total = 0;//userOrderService.selectOrderListByBizUserCount(null, biz_user_id, status, pay_status);

        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("page", page);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/orderDetailManage")
    public String orderDetailManage(@RequestParam(value = "order_id",required = false) Integer order_id,
                                    Model model) {
        model.addAttribute("order_id", order_id);

        return PREFIX + "orderDetailManage";
    }

    @RequestMapping(value = "/getOrderDetailList")
    public void getOrderDetailList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                             @RequestParam(value = "user_id",required = false) Integer user_id,
                             @RequestParam(value = "order_id",required = false) Integer order_id,
                             Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

//        User user = getCurrentUser();
//        List<ByUserOrderDetail> list = userOrderService.selectOrderDetailListByPage(user_id, order_id, (page-1)*pageSize, pageSize);

        List<ByUserOrderDetailInfoBvo> list = new ArrayList<ByUserOrderDetailInfoBvo>();
        List<ByUserOrderDetail> byUserOrders = userOrderService.selectOrderDetailListByPage(user_id, order_id, (page-1)*pageSize, pageSize);
        if (byUserOrders != null && byUserOrders.size()>0){
            for(ByUserOrderDetail current : byUserOrders){
                list.add(ByUserOrderDetailInfoBvo.copyFrom(current, userService.selectUserById(current.getUserId()),
                        userService.selectUserById(current.getBizUserId()), userService.findBizProduct(current.getProductId())));
            }
        }

        int total = userOrderService.selectOrderDetailListCount(user_id, order_id);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/myOrder")
    public String myOrder(Model model) {
        model.addAttribute("statusList", OrderStatus.getAllData());
        model.addAttribute("payStatusList", OrderPayStatus.getAllData());

        return PREFIX + "myOrder";
    }

    @RequestMapping(value = "/getMyOrderList")
    public void getMyOrderList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "50") Integer pageSize,
                             @RequestParam(value = "status",required = false) Integer status,
                             @RequestParam(value = "pay_status",required = false) Integer pay_status,
                             Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserOrderInfoBvo> list = new ArrayList<ByUserOrderInfoBvo>();
        List<ByUserOrder> byUserOrders = userOrderService.selectOrderListByPage(user.getId(), status, pay_status, (page-1)*pageSize, pageSize);
        if (byUserOrders != null && byUserOrders.size()>0){
            for(ByUserOrder current : byUserOrders){
                User bizUser = userService.selectUserById(current.getBizUserId());
                list.add(ByUserOrderInfoBvo.copyFrom(current, userService.selectUserById(current.getUserId()),
                        UserInfoBvo.copyFrom(bizUser, null, contentService.findChannel(bizUser.getBizWorkType()))));
            }
        }

        int total = userOrderService.selectOrderListCount(user.getId(), status, pay_status);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/submitOrder")
    public String submitOrder(@RequestParam(value = "pay_type", defaultValue = "1") Integer pay_type,
                              RedirectAttributes redirectAttributes,Model model) {
        try{
            User user = getCurrentUser();

            List<ByUserTrolley> byUserTrolleys = userService.selectTrolleyListByPage(user.getId(), 0, Integer.MAX_VALUE);


            Map<Integer, List<ByUserTrolley>> tmpMap = new HashMap<Integer, List<ByUserTrolley>>();
            if (byUserTrolleys !=null && byUserTrolleys.size() > 0){
                Set set = new HashSet();

                for (ByUserTrolley current : byUserTrolleys){
                    if(set.contains(current.getBizUserId())){
                        tmpMap.get(current.getBizUserId()).add(current);
                    }else{
                        List<ByUserTrolley> tmpList = new ArrayList<ByUserTrolley>();
                        tmpList.add(current);
                        tmpMap.put(current.getBizUserId(), tmpList);

                        set.add(current.getBizUserId());
                    }
                }

                for(Iterator it = tmpMap.keySet().iterator(); it.hasNext();) {
                    Integer mKey = (Integer) it.next();
                    User currentBizUser = userService.selectUserById(mKey);

                    ByUserOrder order = new ByUserOrder();
                    order.setUserId(user.getId());

                    order.setPayType(pay_type);
                    order.setPayStatus(OrderPayStatus.NOT_PAY.getCode());
                    order.setBizUserId(mKey);
                    order.setCreateTime(new DateTime());
                    order.setUpdateTime(new DateTime());

                    userOrderService.insertByUserOrder(order);

                    BigDecimal orderPrice = BigDecimal.ZERO;

                    StringBuffer descnSb = new StringBuffer();

                    for (ByUserTrolley current : tmpMap.get(mKey)){
                        ByUserBizProduct byUserBizProduct = userService.findBizProduct(current.getProductId());

                        if (StringUtils.isNotBlank(current.getDescn())){
                            descnSb.append(current.getDescn());
                        }

                        ByUserOrderDetail detail = new ByUserOrderDetail();
                        detail.setOrderId(order.getId());
                        detail.setUserId(user.getId());

                        if(current.getAmount() == null || current.getAmount() < 1){
                            detail.setAmount(1);
                        }else{
                            detail.setAmount(current.getAmount());
                        }

                        detail.setProductId(current.getProductId());
                        detail.setPrice(byUserBizProduct.getCurrentPrice().multiply(new BigDecimal(current.getAmount())));

                        orderPrice = orderPrice.add(detail.getPrice());

                        detail.setScheduleDate(current.getScheduleDate());
                        detail.setDinnerType(current.getDinnerType());
                        detail.setBizUserId(byUserBizProduct.getUserId());
                        detail.setOrderId(order.getId());
                        detail.setDeposit(Constants.PRODUCT_DEPOSIT_RATIO.multiply(detail.getPrice()));
                        detail.setCreateTime(new DateTime());
                        detail.setUpdateTime(new DateTime());
                        userOrderService.insertByUserOrderDetail(detail);

                        //add Schedule
                        ByUserBizSchedule byUserBizSchedule = new ByUserBizSchedule();
                        byUserBizSchedule.setUserId(current.getBizUserId());
                        byUserBizSchedule.setScheduleDate(detail.getScheduleDate());
                        byUserBizSchedule.setStatus(BaseState.NORMAL.getCode());
                        byUserBizSchedule.setScheduleType(ScheduleType.getByName(detail.getDinnerType()).getCode());
                        byUserBizSchedule.setOrderBy(detail.getUserId());
                        byUserBizSchedule.setCreateTime(new DateTime());
                        byUserBizSchedule.setUpdateTime(new DateTime());

                        userOrderService.insertSchedule(byUserBizSchedule);
                    }

                    ByUserOrder newOrder = userOrderService.findByUserOrder(order.getId());

                    //更新订单价格
                    newOrder.setPrice(orderPrice);
                    newOrder.setDescn(descnSb.toString());
                    if (currentBizUser.getBizWorkType().intValue() == 1){ //策划师
                        newOrder.setStatus(OrderStatus.NEW_ORDER.getCode());
                    }else{
                        newOrder.setStatus(OrderStatus.VERIFY_ORDER.getCode());
                    }
                    newOrder.setDeposit(Constants.PRODUCT_DEPOSIT_RATIO.multiply(newOrder.getPrice()));
                    newOrder.setNeedPayPrice(newOrder.getPrice().subtract(newOrder.getDeposit()));

                    userOrderService.insertByUserOrder(newOrder);
                }
            }

            userService.deleteTrolleyByUserAndProduct(user.getId(), null);

            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }
//        redirectAttributes.addAttribute("message", "订单提交成功,请到后台查看!");
        redirectAttributes.addFlashAttribute("message", "订单提交成功,请到后台查看!");


//        RedirectView redirect = new RedirectView("/index");
//        redirect.setExposeModelAttributes(false);

        return "redirect:/main?src=/order/myOrder";
    }

    @RequestMapping(value = "/addDirectBuy")
    public String addDirectBuy(@RequestParam(value = "product_id",required = false) Integer product_id,
                               @RequestParam(value = "biz_user_id",required = false) Integer biz_user_id,
                               @RequestParam(value = "schedule_date",required = false) String schedule_date,
                               @RequestParam(value = "dinner_type",required = false) String dinner_type,
                               @RequestParam(value = "qty_item_1",defaultValue = "1") Integer qty_item_1,
                               @RequestParam(value = "descn",required = false) String descn,
                               @RequestParam(value = "pay_status",required = false) Integer pay_status,
                               Model model) {

        User user = getCurrentUser();

//        if (biz_user_id == null || biz_user_id < 1 || (biz_user_id.intValue() == user.getId().intValue())){
//            return "";
//        }

        ByUserOrder order = new ByUserOrder();
        if (product_id != null && product_id > 0) {
            ByUserBizProduct byUserBizProduct = userService.findBizProduct(product_id);
            User currentBizUser = userService.selectUserById(biz_user_id);

            order.setUserId(user.getId());

            order.setPayType(PayType.ALIPAY.getCode());
            order.setPayStatus(OrderPayStatus.NOT_PAY.getCode());
            order.setBizUserId(biz_user_id);
            order.setDescn(descn);
            order.setCreateTime(new DateTime());
            order.setUpdateTime(new DateTime());

            BigDecimal orderPrice = BigDecimal.ZERO;


            //更新订单价格
            if(qty_item_1 == null || qty_item_1 < 1){
                qty_item_1 = 1;
            }

            order.setPrice(byUserBizProduct.getCurrentPrice().multiply(new BigDecimal(qty_item_1)));
            if (currentBizUser.getBizWorkType().intValue() == 1){ //策划师
                order.setStatus(OrderStatus.NEW_ORDER.getCode());
            }else{
                order.setStatus(OrderStatus.VERIFY_ORDER.getCode());
            }

            if (pay_status.intValue() == OrderPayStatus.PAY_ALL.getCode()) {
                order.setDeposit(order.getPrice());
                order.setNeedPayPrice(BigDecimal.ZERO);
            }else{
                order.setDeposit(Constants.PRODUCT_DEPOSIT_RATIO.multiply(order.getPrice()));
                order.setNeedPayPrice(order.getPrice().subtract(order.getDeposit()));
            }

            userOrderService.insertByUserOrder(order);


            //insert order detail

            ByUserOrderDetail detail = new ByUserOrderDetail();
            detail.setOrderId(order.getId());
            detail.setUserId(user.getId());
            detail.setProductId(product_id);
            detail.setAmount(qty_item_1);
            detail.setPrice(order.getPrice());

            detail.setScheduleDate(DateUtil.getDateTime(schedule_date));
            detail.setDinnerType(dinner_type);
            detail.setBizUserId(byUserBizProduct.getUserId());
            detail.setOrderId(order.getId());
            detail.setDeposit(Constants.PRODUCT_DEPOSIT_RATIO.multiply(detail.getPrice()));
            detail.setCreateTime(new DateTime());
            detail.setUpdateTime(new DateTime());
            userOrderService.insertByUserOrderDetail(detail);

            //add Schedule
            ByUserBizSchedule byUserBizSchedule = new ByUserBizSchedule();
            byUserBizSchedule.setUserId(biz_user_id);
            byUserBizSchedule.setScheduleDate(detail.getScheduleDate());
            byUserBizSchedule.setStatus(BaseState.NORMAL.getCode());
            byUserBizSchedule.setScheduleType(ScheduleType.getByName(detail.getDinnerType()).getCode());
            byUserBizSchedule.setOrderBy(detail.getUserId());
            byUserBizSchedule.setCreateTime(new DateTime());
            byUserBizSchedule.setUpdateTime(new DateTime());

            userOrderService.insertSchedule(byUserBizSchedule);

        }

        return "redirect:"+ PREFIX + "orderPay?order_id="+order.getId()+"&status="+pay_status;
    }

    @RequestMapping(value = "/addDescnView")
    public String addDescn(@RequestParam(value = "order_id",required = false) Integer order_id,
                                    Model model) {
        if (order_id !=null && order_id > 0) {
            model.addAttribute("order", userOrderService.findByUserOrder(order_id));
        }

        return PREFIX + "addDescnView";
    }

    @RequestMapping(value = "/submitDescn")
    public String addDescn(@RequestParam(value = "order_id",required = false) Integer order_id,
                           @RequestParam(value = "descn",required = false) String descn,
                           Model model) {
        if (order_id !=null && order_id > 0) {
            ByUserOrder byUserOrder = userOrderService.findByUserOrder(order_id);
            byUserOrder.setDescn(descn);

            userOrderService.insertByUserOrder(byUserOrder);
        }

        return PREFIX + "myOrder";
    }

    @RequestMapping(value = "/addOrderComment")
    public String addOrderComment(@RequestParam(value = "order_id",required = false) Integer order_id,
                                  Model model) {
        if (order_id !=null && order_id > 0) {
            model.addAttribute("order", userOrderService.findByUserOrder(order_id));
        }

        return PREFIX + "addOrderComment";
    }

    @RequestMapping(value = "/submitOrderComment")
    public String submitOrderComment(@RequestParam(value = "order_id",required = false) Integer order_id,
                            @RequestParam(value = "user_stars",defaultValue = "5") Integer user_stars,
                           @RequestParam(value = "descn",required = false) String descn,
                           Model model) {
        if (order_id !=null && order_id > 0) {
            ByUserOrder byUserOrder = userOrderService.findByUserOrder(order_id);
            byUserOrder.setUserStars(user_stars);
            byUserOrder.setUserComment(descn);

            userOrderService.insertByUserOrder(byUserOrder);
        }

        return PREFIX + "myOrder";
    }

    //Schedule
    @RequestMapping(value = "/addScheduleView")
    public String addScheduleView(@RequestParam(value = "id",required = false) Integer id,
                                Model model) {

        model.addAttribute("scheduleTypeList", ScheduleType.getAllData());

        return PREFIX + "addScheduleView";
    }

    @RequestMapping(value = "/editScheduleView")
    public String editScheduleView(@RequestParam(value = "id",required = false) Integer id,
                                 Model model) {

        if (id != null && id > 0){
            model.addAttribute("bizSchedule", userOrderService.findSchedule(id));
        }

        model.addAttribute("scheduleTypeList", ScheduleType.getAllData());

        return PREFIX + "editScheduleView";
    }

    @RequestMapping(value = "/deleteSchedule")
    public String deleteSchedule(@RequestParam(value = "id",required = true) Integer id,
                                   Model model) {

        if (id != null && id > 0){
            userOrderService.deleteSchedule(id);
        }

        return PREFIX + "mySchedule";
    }

    @RequestMapping(value = "/submitSchedule")
    public String submitSchedule(@RequestParam(value = "id",required = false) Integer id,
                               @RequestParam(value = "user_id",required = false) Integer user_id,
                               @RequestParam(value = "schedule_date",required = false) String schedule_date,
                               @RequestParam(value = "schedule_type",required = false) Integer schedule_type,
                               @RequestParam(value = "status",defaultValue = "-1") Integer status,
                               Model model) {
        try{
            User user = getCurrentUser();
//            boolean isScheduled = userOrderService.isScheduled(user.getId(), BaseState.NORMAL.getCode(), DateUtil.getDateTime(schedule_date), schedule_type);
//            if (isScheduled){
//                model.addAttribute("result", "档期已被预订,不能添加!");
//                return PREFIX + "mySchedule";
//            }

            ByUserBizSchedule byUserBizSchedule = null;
            if (id != null && id > 0){
                byUserBizSchedule = userOrderService.findSchedule(id);
            }else{
                byUserBizSchedule = new ByUserBizSchedule();
            }
            byUserBizSchedule.setUserId(user.getId());
            byUserBizSchedule.setScheduleDate(DateUtil.getDateTime(schedule_date));
            byUserBizSchedule.setStatus(BaseState.DELETE.getCode());
            byUserBizSchedule.setScheduleType(schedule_type);
            byUserBizSchedule.setCreateTime(new DateTime());
            byUserBizSchedule.setUpdateTime(new DateTime());

            userOrderService.insertSchedule(byUserBizSchedule);
            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }
        return PREFIX + "mySchedule";
    }


    @RequestMapping(value = "/scheduleManage")
    public String scheduleManage() {
        return PREFIX + "scheduleManage";
    }

    @RequestMapping(value = "/getScheduleList")
    public void getScheduleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                             Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

//        User user = getCurrentUser();
        List<ByUserBizScheduleBvo> list = new ArrayList<ByUserBizScheduleBvo>();
        List<ByUserBizSchedule> bizSchedules = userOrderService.selectScheduleListByPage(null, null, (page-1)*pageSize, pageSize);
        if (bizSchedules != null && bizSchedules.size() > 0){
            for(ByUserBizSchedule current : bizSchedules){
                ByUserBizScheduleBvo bvo = ByUserBizScheduleBvo.copyFrom(current, userService.selectUserById(current.getUserId()));
                list.add(bvo);
            }
        }


        int total = userOrderService.selectScheduleListCount(null, null);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/mySchedule")
    public String mySchedule() {
        return PREFIX + "mySchedule";
    }

    @RequestMapping(value = "/getMyScheduleList")
    public void getMyScheduleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                             Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
        List<ByUserBizSchedule> list = userOrderService.selectScheduleListByPage(user.getId(),null, (page-1)*pageSize, pageSize);
        int total = userOrderService.selectScheduleListCount(user.getId(),null);
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    @RequestMapping(value = "/redPacketView")
    public String redPacketView(@RequestParam(value = "id",required = false) Integer id,
                                @RequestParam(value = "user_id",required = false) Integer user_id,
                                Model model) {
        model.addAttribute("order_id", id);
        model.addAttribute("user_id", user_id);

        model.addAttribute("redPacketTypeList", RedPacketType.getAllData());

        return PREFIX + "redPacketView";
    }

    @RequestMapping(value = "/sendRedPacket")
    public String sendRedPacket(@RequestParam(value = "id",required = false) Integer id,
                                 @RequestParam(value = "user_id",required = false) Integer user_id,
                                @RequestParam(value = "red_packet_type",required = false) Integer red_packet_type,
                                 @RequestParam(value = "red_packet_money",required = false) String red_packet_money,
                                 Model model) {
        try{
            ByUserOrder byUserOrder = null;
            if (id != null && id > 0){
                byUserOrder = userOrderService.findByUserOrder(id);
            }else{
                byUserOrder = new ByUserOrder();
            }
            byUserOrder.setRedPacketMoney(ObjectFormatter.str2BigDecimal(red_packet_money));
            byUserOrder.setUpdateTime(new DateTime());

            userOrderService.insertByUserOrder(byUserOrder);

            if (red_packet_type != null && red_packet_type.intValue() != 1 && Float.parseFloat(red_packet_money) > 0) {
                ByMoneyLog byMoneyLog = new ByMoneyLog();
                byMoneyLog.setUserId(user_id);
                byMoneyLog.setAmount(ObjectFormatter.str2BigDecimal(red_packet_money));
                byMoneyLog.setMoneyType(MoneyType.RED_PACKET.getCode());
                byMoneyLog.setCreateTime(new DateTime());
                byMoneyLog.setUpdateTime(new DateTime());
                accountService.insertMoneyLog(byMoneyLog);

                User user = getCurrentUser();
                user.setMoney(user.getMoney().add(ObjectFormatter.str2BigDecimal(red_packet_money)));
                userService.updateUser(user);
            }

            model.addAttribute("result", true);
        }catch (Exception ex){
            ex.printStackTrace();
            model.addAttribute("result", false);
        }
        return PREFIX + "myOrder";
    }

    /**
     * 账户充值
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(value="/accountRecharge")
    public void accountRecharge(HttpServletRequest request, HttpServletResponse response) throws IOException{

        LOG.debug("支付宝支付服务器异步通知请求    orderNum="+request.getParameter("out_trade_no"));
        PrintWriter out = response.getWriter();

        //获取支付宝POST过来反馈信息
        Map<String,String> params= AlipayParams.getAlipayParamsForMap(request);
//		AccountChange  accountChange =AlipayParams.getAlipayParamsForAccountChange(params);
//		String trade_status=accountChange.getAlipayTradeStatus();
//
//		if(Env.unitTest || ( params.size()>=1 && AlipayNotify.verify(params) && params.get("notify_type")!=null && params.get("notify_type").trim().equals("trade_status_sync") )){
//			/**
//			 * a、在支付宝的业务通知中，只有交易通知状态为 TRADE_SUCCESS或TRADE_FINISHED  时，支付宝才会认定为买家付款成功
//			 * b、交易状态 TRADE_SUCCESS 的通知触发条件是商户签约的产品支持退款功能的前提下，买家付款成功；
//			 * c、交易状态 TRADE_FINISHED 的通知触发条件是商户签约的产品不支持退款功能的前提下，买家付款成功；或者，商户签约的产品支持退款功能的前提下，交易已经成功并且已经超过可退款期限；
//			 */
//			if( trade_status!=null && (trade_status.trim().equals("TRADE_FINISHED") || trade_status.trim().equals("TRADE_SUCCESS"))){
//				LOG.debug("支付宝(支付完成;买家付款成功)异步通知: success");
////				accountService.accountRecharge(accountChange);
////				out.println("success".toString().trim());	//请不要修改或删除
//				out.print("success".toString().trim());	//请不要修改或删除
//			}else{
//				LOG.debug("支付(卖买家付款还未完成)宝异步通知: trade_status="+trade_status);
//				out.print("fail".toString().trim());
//			}
//		}else{
//			LOG.debug("支付宝异步通知校验不合法: fail--数字校验未通过");
//			out.print("fail".toString().trim());
//		}
    }

    /**
     * 订单支付
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(value="/orderPay")
    public String ordersPay(
            @RequestParam(value = "order_id",required = true) String order_id,
            @RequestParam(value = "status",required = true) Integer status,
            HttpServletRequest request, HttpServletResponse response,
            Model model) throws IOException{

        User user = getCurrentUser();
        if (StringUtils.isBlank(order_id)){
            return "accessDenied";
        }

        Map<String, String> sParaTemp = new HashMap<String, String>();
        sParaTemp.put("service", AlipayConfig.service);
        sParaTemp.put("partner", AlipayConfig.partner);
        sParaTemp.put("seller_id", AlipayConfig.seller_id);
        sParaTemp.put("_input_charset", AlipayConfig.input_charset);
        sParaTemp.put("payment_type", AlipayConfig.payment_type);
        sParaTemp.put("notify_url", AlipayConfig.notify_url);
        sParaTemp.put("return_url", AlipayConfig.return_url);
        sParaTemp.put("anti_phishing_key", AlipayConfig.anti_phishing_key);
        sParaTemp.put("exter_invoke_ip", AlipayConfig.exter_invoke_ip);


        if (order_id.indexOf(",") != -1){
            String orderIds[] = order_id.split(",");

            if (orderIds != null && orderIds.length > 0){
                //add batch order
                BigDecimal totalPrice = BigDecimal.ZERO;
                BigDecimal totalDeposit = BigDecimal.ZERO;

                List<Integer> orderIdList = new ArrayList<Integer>();
                for (int i = 0; i < orderIds.length; i++) {
                    orderIdList.add(Integer.valueOf(orderIds[i]));
                }
                List<ByUserOrder> orderList = userOrderService.findByUserOrderList(orderIdList);

                for (ByUserOrder current : orderList){
                    totalPrice = totalPrice.add(current.getPrice());
                    totalDeposit = totalDeposit.add(current.getDeposit());
                }

                ByUserBatchPayOrder batchOrder = new ByUserBatchPayOrder();
                batchOrder.setUserId(user.getId());
                batchOrder.setBatchNum("bt-"+ MD5Util.Md5(DateUtil.dateToString(new DateTime())+ RandCharUtil.getRandStr(8)));
                batchOrder.setOrderIds(order_id);
                batchOrder.setPrice(totalPrice);
                batchOrder.setPriceType(status);
                batchOrder.setCreateTime(new DateTime());
                batchOrder.setUpdateTime(new DateTime());
                batchOrder.setDescn("批量订单支付");
                batchOrder.setStatus(BaseState.DELETE.getCode());  //未付款

                userOrderService.insertByUserBatchPayOrder(batchOrder);

                sParaTemp.put("out_trade_no", batchOrder.getBatchNum());
                sParaTemp.put("subject", "博艺网订单_"+batchOrder.getBatchNum());

                if (status.intValue() == OrderPayStatus.PAY_ALL.getCode()){
                    sParaTemp.put("total_fee", totalPrice.toString());
                }else{
                    sParaTemp.put("total_fee", totalDeposit.toString());
                }
                sParaTemp.put("body", batchOrder.getDescn());
            }
        }else{
            ByUserOrder byUserOrder = userOrderService.findByUserOrder(Integer.valueOf(order_id));

            sParaTemp.put("out_trade_no", order_id);
            sParaTemp.put("subject", "博艺网订单_"+order_id);

            if (status.intValue() == OrderPayStatus.PAY_ALL.getCode()){
                sParaTemp.put("total_fee", byUserOrder.getPrice().toString());
            }else{
                sParaTemp.put("total_fee", byUserOrder.getDeposit().toString());
            }
            sParaTemp.put("body", byUserOrder.getDescn());
        }



        //其他业务参数根据在线开发文档，添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
        //如sParaTemp.put("参数名","参数值");

        //建立请求
        String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,"get","确认");

        model.addAttribute("sHtmlText", sHtmlText);
//        PrintWriter out = response.getWriter();
//        out.println(sHtmlText);
        return PREFIX + "orderPayResult";
    }

    @RequestMapping(value = "/orderPayResult")
    public String orderPayResult(Model model) {
        UserForm userForm = new UserForm();
        model.addAttribute("userForm", userForm);
//        model.addAttribute("misName", misName);
        return PREFIX + "orderPayResult";
    }

//    /**
//     * 商家子订单退款异步通知接口
//     * @param request
//     * @param response
//     * @throws IOException
//     */
//    @RequestMapping(value="/notify_url")
//    public void notifyUrl(HttpServletRequest request, HttpServletResponse response) throws IOException{
//        LOG.debug("支付宝支付服务器异步通知请求    orderNum="+request.getParameter("out_trade_no"));
//        PrintWriter out = response.getWriter();
//
//        //获取支付宝POST过来反馈信息
//        Map<String,String> params= AlipayParams.getAlipayParamsForMap(request);
//        ByUserOrder  orders =AlipayParams.getAlipayParamsForOrder(params);
//        String trade_status=orders.getAlipaytradestatus();
//
//        if(Constants.IS_DEBUG || (params.size()>=1 && AlipayNotify.verify(params) && params.get("notify_type")!=null && params.get("notify_type").trim().equals("trade_status_sync") )){
//            /**
//             * a、在支付宝的业务通知中，只有交易通知状态为 TRADE_SUCCESS或TRADE_FINISHED  时，支付宝才会认定为买家付款成功
//             * b、交易状态 TRADE_SUCCESS 的通知触发条件是商户签约的产品支持退款功能的前提下，买家付款成功；
//             * c、交易状态 TRADE_FINISHED 的通知触发条件是商户签约的产品不支持退款功能的前提下，买家付款成功；或者，商户签约的产品支持退款功能的前提下，交易已经成功并且已经超过可退款期限；
//             */
//            if( trade_status!=null && (trade_status.trim().equals("TRADE_FINISHED") || trade_status.trim().equals("TRADE_SUCCESS"))){
//                LOG.debug("支付宝(支付完成;买家付款成功)异步通知: success");
//                orders.setPayType(Const.OrdersPayMethod.ALIPAY);
//
//                ByUserOrder oldOrder = userOrderService.findByUserOrder(Integer.valueOf(orders.getAlipaytradeno()));
//
//                orders.setNeedPayPrice(oldOrder.getPrice().subtract(orders.getAlipaytotalfee()));
//
//                if (orders.getNeedPayPrice().equals(BigDecimal.ZERO)){
//                    orders.setPayStatus(OrderPayStatus.PAY_ALL.getCode());
//                }else {
//                    orders.setPayStatus(OrderPayStatus.PAY_DEPOSIT.getCode());
//                }
//
//                userOrderService.insertByUserOrder(orders);
//
////				out.println("success".toString().trim());	//请不要修改或删除
//                out.print("success".toString().trim());	//请不要修改或删除
//            }else{
//                LOG.debug("支付(卖买家付款还未完成)宝异步通知: trade_status="+trade_status);
//                out.print("fail".toString().trim());
//            }
//        }else{
//            LOG.debug("支付宝异步通知校验不合法: fail--数字校验未通过");
//            out.print("fail".toString().trim());
//        }
//    }
//
//    /**
//     * 商家子订单退款同步通知接口
//     * @param request
//     * @param response
//     * @throws IOException
//     */
//    @RequestMapping(value="/return_url")
//    public void returnUrl(HttpServletRequest request, HttpServletResponse response) throws IOException{
//        LOG.debug("支付宝支付服务器同步通知请求    orderNum="+request.getParameter("out_trade_no"));
//        PrintWriter out = response.getWriter();
//
//        //获取支付宝POST过来反馈信息
//        Map<String,String> params= AlipayParams.getAlipayParamsForMap(request);
//        ByUserOrder  orders =AlipayParams.getAlipayParamsForOrder(params);
//        String trade_status=orders.getAlipaytradestatus();
//
//        if(Constants.IS_DEBUG || (params.size()>=1 && AlipayNotify.verify(params) && params.get("notify_type")!=null && params.get("notify_type").trim().equals("trade_status_sync") )){
//            /**
//             * a、在支付宝的业务通知中，只有交易通知状态为 TRADE_SUCCESS或TRADE_FINISHED  时，支付宝才会认定为买家付款成功
//             * b、交易状态 TRADE_SUCCESS 的通知触发条件是商户签约的产品支持退款功能的前提下，买家付款成功；
//             * c、交易状态 TRADE_FINISHED 的通知触发条件是商户签约的产品不支持退款功能的前提下，买家付款成功；或者，商户签约的产品支持退款功能的前提下，交易已经成功并且已经超过可退款期限；
//             */
//            if( trade_status!=null && (trade_status.trim().equals("TRADE_FINISHED") || trade_status.trim().equals("TRADE_SUCCESS"))){
//                LOG.debug("支付宝(支付完成;买家付款成功)同步通知: success");
////                orders.setPayType(Const.OrdersPayMethod.ALIPAY);
//
//                ByUserOrder oldOrder = userOrderService.findByUserOrder(Integer.valueOf(orders.getAlipaytradeno()));
//
//                orders.setNeedPayPrice(oldOrder.getPrice().subtract(orders.getAlipaytotalfee()));
//
//                if (orders.getNeedPayPrice().equals(BigDecimal.ZERO)){
//                    orders.setPayStatus(OrderPayStatus.PAY_ALL.getCode());
//                }else {
//                    orders.setPayStatus(OrderPayStatus.PAY_DEPOSIT.getCode());
//                }
//
//                userOrderService.insertByUserOrder(orders);
//
////				out.println("success".toString().trim());	//请不要修改或删除
//                out.print("success".toString().trim());	//请不要修改或删除
//            }else{
//                LOG.debug("支付(卖买家付款还未完成)宝同步通知: trade_status="+trade_status);
//                out.print("fail".toString().trim());
//            }
//        }else{
//            LOG.debug("支付宝同步通知校验不合法: fail--数字校验未通过");
//            out.print("fail".toString().trim());
//        }
//    }

//    /**
//     * 商家子订单退款异步通知接口
//     * @param request
//     * @param response
//     * @throws IOException
//     */
//    @RequestMapping(value="/orderBusinessRefund")
//    public void orderBusinessRefund(HttpServletRequest request, HttpServletResponse response) throws IOException{
//
////        LOG.debug("doRequest(interface/orderBusinessRefund)--支付宝支付服务器(退款)异步通知请求");
////        PrintWriter out = response.getWriter();
////
////        //获取支付宝POST过来反馈信息
////        Map<String,String>  params=AlipayParams.getAlipayParamsForMap(request);
////        OrdersBusiness  ordersBusiness =AlipayParams.getAlipayParamsForOrdersBusiness(params);
////        String trade_status=params.get("trade_status");
////
////
////        if(Env.unitTest || (params.size()>=1 && AlipayNotify.verify(params))){
////            if(params.get("notify_type")!=null && params.get("notify_type").trim().equals("trade_status_sync")){
////                if(trade_status!=null && (trade_status.trim().equals("TRADE_CLOSED"))){
////                    //交易关闭处理，即用户已完成了全部退款
////                    LOG.debug("支付宝(交易关闭处理，即用户已完成了全部退款)异步通知: success");
////                }else{
////                    LOG.debug("支付宝(交易未关闭，执行了部分退款操作)异步通知: success");
////                }
////                out.print("success");	//请不要修改或删除
////                return;
////            }else if(params.get("notify_type")!=null && params.get("notify_type").trim().equals("batch_refund_notify")){
////                String  result_details=params.get("result_details");
////                if(result_details==null){
////                    LOG.debug("支付宝退款返回的退款详细信息错误： result_details=" +result_details);
////                    out.print("fail");
////                    return;
////                }
////                String[] result_detailsArray=result_details.split("^");
////                if(result_detailsArray.length<=3 || !result_detailsArray[2].trim().equals("SUCCESS")){
////                    LOG.debug("支付宝退款返回的退款详细信息错误： result_details=" +result_details);
////                    out.print("fail");
////                    return;
////                }
////
////                if(result_detailsArray[2].trim().equals("SUCCESS")){
////
////                    //退款成功后业务操作
////                    ordersService.doOrdersBusinessRefund(ordersBusiness);
////                    LOG.debug("支付宝(该笔退款成功)退款异步通知： success");
////                    out.print("success");	//请不要修改或删除
////                    return;
////                }
////
////
////            }else{
////                LOG.debug("支付宝(退款)异步通知校验不合法: fail---notify_type="+params.get("notify_type"));
////                out.print("fail");
////                return;
////            }
////
////        }else{
////            LOG.debug("支付宝(退款)异步通知校验不合法: fail---数字验签未通过");
////            out.print("fail");
////            return;
////        }
//
//    }

    @RequestMapping(value = "/orderCancel")
    public void orderCancel(@RequestParam(value = "order_id", required = true) Integer order_id,
                            Model model) {
        User user = getCurrentUser();
//        List<ByUserVoucher> list = accountService.selectVoucherListByPage(user.getId(), (page-1)*pageSize, pageSize);
//        int total = accountService.selectVoucherListCount(user.getId());
//        model.addAttribute("list", list);
//        model.addAttribute("total", total);
//        model.addAttribute("pageSize", pageSize);
    }

    //for admin use
    @RequestMapping(value = "/orderAdminChangeStatus")
    public String orderAdminChangeStatus(@RequestParam(value = "order_id", required = true) Integer order_id,
                                    @RequestParam(value = "status", required = true) Integer status,
                                    Model model) {
        if (order_id != null && status != null){
            User user = getCurrentUser();

            ByUserOrder order = userOrderService.findByUserOrder(order_id);

            if (order != null) {
                order.setStatus(status);
                order.setUpdateTime(new DateTime());

                userOrderService.insertByUserOrder(order);

                if (status == OrderStatus.VERIFY_ORDER.getCode()){
                    User bizUser = userService.selectUserById(order.getBizUserId());

                    //send msg
                    Map<String, Object> map = new LinkedHashMap<String, Object>();
                    map.put("code", ""+status);

                    CommonUtil.sendMessage(bizUser.getMobile(), JSONObject
                            .fromObject(map).toString(), ConfigUtil
                            .getSms_template_code_new_order());
                }

//                if (status == OrderStatus.VERIFY_ORDER.getCode()) {
//                    User bizUser = userService.selectUserById(order.getBizUserId());
//
//                    if (bizUser.getBizDealCount() != null && bizUser.getBizDealCount() > 0) {
//                        bizUser.setBizDealCount(bizUser.getBizDealCount() + 1);
//                    } else {
//                        bizUser.setBizDealCount(1);
//                    }
//                    userService.updateUser(bizUser);
//                }
            }
        }

        return PREFIX + "orderManage";
    }

    //for user use
    @RequestMapping(value = "/orderChangeStatus")
    public String orderChangeStatus(@RequestParam(value = "order_id", required = true) Integer order_id,
                                    @RequestParam(value = "status", required = true) Integer status,
                                    Model model) {
        if (order_id != null && status != null){
            User user = getCurrentUser();

            ByUserOrder order = userOrderService.findByUserOrder(order_id);

            if (user.getId().intValue() == order.getUserId().intValue()) {

                order.setStatus(status);
                order.setUpdateTime(new DateTime());

                userOrderService.insertByUserOrder(order);

                if (status == OrderStatus.CONFIRM_ORDER.getCode()){
                    User bizUser = userService.selectUserById(order.getBizUserId());

                    if (bizUser.getBizDealCount() != null && bizUser.getBizDealCount() > 0) {
                        bizUser.setBizDealCount(bizUser.getBizDealCount() + 1);
                    }else{
                        bizUser.setBizDealCount(1);
                    }

                    BigDecimal commission = BigDecimal.ZERO;

                    if (order.getPayStatus().intValue() == OrderPayStatus.PAY_ALL.getCode()){
                        commission = order.getPrice().multiply(BigDecimal.ONE.subtract(Constants.BIZ_USER_COMMISSION_RATIO));
                    }else if(order.getPayStatus().intValue() == OrderPayStatus.PAY_DEPOSIT.getCode()){
                        commission = order.getDeposit().subtract(order.getPrice().multiply(Constants.BIZ_USER_COMMISSION_RATIO));
                    }

                    if (bizUser.getMoney() == null || bizUser.getMoney() == BigDecimal.ZERO) {
                        bizUser.setMoney(commission);
                    }else{
                        bizUser.setMoney(bizUser.getMoney().add(commission));
                    }
                    writeMoneyLog(bizUser, MoneyType.PAY_ORDER.getCode(), commission);
                    userService.updateUser(bizUser);
                }else if (status == OrderStatus.CANCEL_NOT_REFUND.getCode()){
                    //恢复档期
                    userOrderService.deleteScheduleByOrderId(order_id);
                }
            }
        }

        return PREFIX + "myOrder";
    }

    //for biz use
    @RequestMapping(value = "/orderBizChangeStatus")
    public String orderBizChangeStatus(@RequestParam(value = "order_id", required = true) Integer order_id,
                                  @RequestParam(value = "status", required = true) Integer status,
                                  Model model) {
        if (order_id != null && status != null){
            User user = getCurrentUser();

            ByUserOrder order = userOrderService.findByUserOrder(order_id);

            if (user.getId().intValue() == order.getBizUserId().intValue()) {

                if (status.intValue() == OrderStatus.BIZ_RECEIVE_ORDER.getCode()){
                    User orderUser = userService.selectUserById(order.getUserId());

                    //send msg
                    Map<String, Object> map = new LinkedHashMap<String, Object>();
                    map.put("code", ""+order.getId());

                    CommonUtil.sendMessage(orderUser.getMobile(), JSONObject
                            .fromObject(map).toString(), ConfigUtil
                            .getSms_template_code_order_receive());
                }


                //接单,更新档期
//                if (status.intValue() == OrderStatus.BIZ_RECEIVE_ORDER.getCode()
//                        && user.getUserType().intValue() == UserType.NORMAL_BIZ.getCode()){
//
//                    List<ByUserOrderDetail> byUserOrderDetails = userOrderService.selectOrderDetailListByPage(user.getId(), order_id, 0, Integer.MAX_VALUE);
//                    if (byUserOrderDetails != null && byUserOrderDetails.size() > 0){
//                        for (ByUserOrderDetail current : byUserOrderDetails){
//
//                            boolean isScheduled = userOrderService.isScheduled(user.getId(), BaseState.NORMAL.getCode(),
//                                    current.getScheduleDate(), ScheduleType.getByName(current.getDinnerType()).getCode());
//
//                            if (isScheduled){
//                                model.addAttribute("result", "档期已被预订,不能添加!");
//                                return PREFIX + "bizOrderManage";
//                            }

//                            ByUserBizSchedule byUserBizSchedule = new ByUserBizSchedule();
//                            byUserBizSchedule.setUserId(user.getId());
//                            byUserBizSchedule.setScheduleDate(current.getScheduleDate());
//                            byUserBizSchedule.setStatus(BaseState.NORMAL.getCode());
//                            byUserBizSchedule.setScheduleType(ScheduleType.getByName(current.getDinnerType()).getCode());
//                            byUserBizSchedule.setCreateTime(new DateTime());
//                            byUserBizSchedule.setUpdateTime(new DateTime());
//
//                            userOrderService.insertSchedule(byUserBizSchedule);
//                        }
//                    }
//                }
                order.setStatus(status);
                order.setUpdateTime(new DateTime());

                userOrderService.insertByUserOrder(order);
            }
        }

        return PREFIX + "bizOrderManage";
    }

    @RequestMapping(value = "/bizOrderManage")
    public String bizOrderManage(Model model) {

        model.addAttribute("statusList", OrderStatus.getAllData());
        model.addAttribute("payStatusList", OrderPayStatus.getAllData());

        return PREFIX + "bizOrderManage";
    }

    @RequestMapping(value = "/getBizOrderList")
    public void getBizOrderList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                             Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();
//        List<ByUserOrder> list = userOrderService.selectBizOrderListByPage(user_id, (page-1)*pageSize, pageSize);

        List<ByUserOrderInfoBvo> list = new ArrayList<ByUserOrderInfoBvo>();
        List<ByUserOrder> byUserOrders = userOrderService.selectBizOrderListByPage(user.getId(), OrderStatus.VERIFY_ORDER.getCode(),(page-1)*pageSize, pageSize);
        if (byUserOrders != null && byUserOrders.size()>0){
            for(ByUserOrder current : byUserOrders){
                User bizUser = userService.selectUserById(current.getBizUserId());
                list.add(ByUserOrderInfoBvo.copyFrom(current, userService.selectUserById(current.getUserId()),
                        UserInfoBvo.copyFrom(bizUser, null, contentService.findChannel(bizUser.getBizWorkType()))));
            }
        }


        int total = userOrderService.selectBizOrderListCount(user.getId(), OrderStatus.VERIFY_ORDER.getCode());
        model.addAttribute("list", list);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }


    //订单评论列表
    @RequestMapping(value = "/commentManage")
    public String commentManage() {
        return PREFIX + "commentManage";
    }

    @RequestMapping(value = "/getCommentList")
    public void getCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                               @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                               Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        List<ByUserOrder> commentList = userOrderService.selectOrderListByBizUser(null, null, OrderStatus.CONFIRM_ORDER.getCode(), null,(page-1)*pageSize, pageSize);
        int total = 0;//userOrderService.selectOrderListByBizUserCount(null, null, OrderStatus.CONFIRM_ORDER.getCode(), null);

        List<OrderCommentBvo> detailBvoList = new ArrayList<OrderCommentBvo>();
        if (commentList != null && commentList.size() > 0){
            for (ByUserOrder current : commentList){
                OrderCommentBvo bvo = OrderCommentBvo.copyFrom(current, userService.selectUserById(current.getUserId()));
                detailBvoList.add(bvo);
            }
        }


        model.addAttribute("list", detailBvoList);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }

    //我的评论
    @RequestMapping(value = "/myComment")
    public String myComment() {
        return PREFIX + "myComment";
    }

    @RequestMapping(value = "/getMyCommentList")
    public void getMyCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
                                 Model model) {
        if (pageSize == null || pageSize == 0) {
            pageSize = 20;
        }

        User user = getCurrentUser();

        List<ByUserOrder> commentList = userOrderService.selectOrderListByBizUser(user.getId(), null, OrderStatus.CONFIRM_ORDER.getCode(), null,(page-1)*pageSize, pageSize);
        int total = 0;//userOrderService.selectOrderListByBizUserCount(user.getId(), null, OrderStatus.CONFIRM_ORDER.getCode(),null);

        List<OrderCommentBvo> detailBvoList = new ArrayList<OrderCommentBvo>();
        if (commentList != null && commentList.size() > 0){
            for (ByUserOrder current : commentList){
                OrderCommentBvo bvo = OrderCommentBvo.copyFrom(current, userService.selectUserById(current.getUserId()));
                detailBvoList.add(bvo);
            }
        }

        model.addAttribute("list", detailBvoList);
        model.addAttribute("total", total);
        model.addAttribute("pageSize", pageSize);
    }
}
